-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Implement draggable shapes #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I've run the tests locally using the CircleCI configuration ( Any ideas how I can reproduce the failures locally? |
* Workaround to failure in CircleCI.
This reverts commit 5a62051.
I can reproduce the issue locally by using Firefox 38.0. |
I've fixed the failures in CircleCI!!! |
.selectAll('path[data-index="' + index + '"') | ||
.node(); | ||
return d3.selectAll('.shapelayer path').filter(function() { | ||
return +this.getAttribute('data-index') === index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Nice find @n-riesco !
* Initiate drag move at the shape centre to avoid resizing the shape.
TODO
|
} | ||
} | ||
|
||
function setupDragElement(gd, shapePath, shapeOptions, index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this. Way to flatten the code. Thanks!
* Defined a test case per direction, because a test case for all directions would timeout before completion.
* Update cursor before drag/resize interactions starts, so that the user knows what interactions will be initiated on click.
* The move drag area may be hidden if a shape is partially visible. In these circumstance users could only resize a shape. * With this commit, users can press the shift key to move a shape regardless of the point where they click.
I've been thinking of an algorithm to resize path shapes. Here's a simple proposal:
|
x = evt.clientX - dragBBox.left, | ||
y = evt.clientY - dragBBox.top, | ||
cursor = (w > MINWIDTH && h > MINHEIGHT) ? | ||
dragElement.getCursor(x / w, 1 - y / h) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done here.
|
||
dragElement.init(dragOptions); | ||
|
||
function updateDragMode(evt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. We should add a setCursor
handler for annotations too.
That will deserve a PR of it own. Ticket here: #679
@n-riesco shapes referenced to date axes currently support date string (e.g '2016-06-22') and timestamps (e.g But with on line |
@etpinard Thx for catching that one! I've just pushed a fix and updated the tests to use both date strings and timestamps. |
return function(v) { return convertToPx(v.replace('_', ' ')); }; | ||
return function(v) { | ||
if(v.replace) v = v.replace('_', ' '); | ||
return convertToPx(v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
Great PR. Thanks @n-riesco 🍻 |
moveFn: function(dx, dy) { | ||
if(shapeOptions.type === 'path') { | ||
var moveX = function moveX(x) { return p2x(x2p(x) + dx); }; | ||
if(xa && xa.type === 'date') moveX = encodeDate(moveX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @etpinard,
Is it possible to constrain the drag direction to the x or y plane based on an option value?
Resubmitted PR after:
console.log
from tests,